package com.yuqih.common.websocket;


import javax.servlet.http.HttpSession;
import javax.websocket.Endpoint;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

import org.springframework.web.socket.server.standard.ServerEndpointRegistration;

public class HttpSessionServerEndpointRegistration extends ServerEndpointRegistration {
	
	public HttpSessionServerEndpointRegistration(String path, Class<? extends Endpoint> endpointClass) {
		super(path, endpointClass);
	}

	public HttpSessionServerEndpointRegistration(String path, Endpoint endpoint) {
		super(path, endpoint);
	}
	
	@Override
	public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
		super.modifyHandshake(this, request, response);
		
		HttpSession httpSession = (HttpSession) request.getHttpSession();
		if (httpSession != null) {
			sec.getUserProperties().put(HttpSession.class.getName(), httpSession);
		}
	}

}
